// let petData = require("../Data/宠物 - 商品搜索 - 京东.json");
// let furnitureData = require("../Data/家具 - 商品搜索 - 京东.json");
// let cosmeticsData = require("../Data/美妆 - 商品搜索 - 京东.json");
// let appliancesData = require("../Data/电器 - 商品搜索 - 京东.json");

const MongoClient = require("mongodb").MongoClient;

//连接URL
const URL = "mongodb://localhost:27017";
//数据库名称
const dbName = "SuperMall";
//创建MongoClient客户端连接
client = new MongoClient(URL, {
  useNewUrlParser: true,
  useUnifiedTopology: true,
});
client.connect((err) => {
  if (err) {
    console.log("error Messages is" + err.stack);
    return;
  }
  console.log("连接服务器成功");
  db = client.db(dbName);
});

const insertDocuments = (db, documentName, data, callback) => {
  const doc = db.collection(documentName);
  doc.insertMany(data, (err, result) => {
    console.log("影响条数:", result.result.n);
    callback();
  });
};
